@extends('common.admin_template')

@section('content')
    <div class="boxWidth">
        @include('common.notice_msg')
        <div class="row searchLine">
            <div class="col-xs-6 ">
                <select id="cat" class="searchSelect">
                    <option value="0">全部分类</option>
                    @foreach($Cats as $Cat)
                        <option value="{{$Cat->id}}">{{$Cat->name}}</option>
                    @endforeach
                </select>
                <select id="tag" class="searchSelect">
                    <option value="0">全部标签</option>
                    @foreach($Tags as $Tag)
                        <option value="{{$Tag->id}}">{{$Tag->name}}</option>
                    @endforeach
                </select>
                <button class="btn btn-default searchBtn" id="searchMore">筛选</button>
            </div>
            <div class="col-xs-6 searchInput">
                <input type="text" id="searchInput">
                <button class="btn btn-default searchBtn" id="searchCon">搜索</button>
            </div>
        </div>
            <table class="table table-hover adminTableBg">
                <thead>
                <tr>
                    <th class="col-xs-4">标题</th>
                    <th class="col-xs-2">作者</th>
                    <th class="col-xs-1">分类</th>
                    <th class="col-xs-1">状态</th>
                    <th class="col-xs-1">游览量</th>
                    <th class="col-xs-2">时间</th>
                    <th class="col-xs-1">操作</th>
                </tr>
                </thead>
                <tbody>
                <?php $statusName = ['待审','通过']; ?>
                @foreach($Posts as $post)
                    <tr>
                        <th class="col-xs-4 itemTd">{{$post->title}}</th>
                        <th class="col-xs-2 itemTd">{{$post->author}}</th>
                        <th class="col-xs-1 itemTd">{{$post->tagName}}</th>
                        <th class="col-xs-1 itemTd">{{$statusName[$post->status]}}</th>
                        <th class="col-xs-1 itemTd">{{$post->view}}</th>
                        <th class="col-xs-2 itemTd">{{$post->created_at}}</th>
                        <th class="col-xs-1 itemTd">
                            <a href="{{url('admin/post/edit',['id' => $post->id])}}"><span id="addInput">编辑</span></a>
                            <a href="{{url('admin/post/del',['id' => $post->id])}}"><span class="redColor" id="delInput" onclick="if(!confirm('是否确认删除？'))return false">删除</span></a>
                        </th>
                    </tr>
                @endforeach
                </tbody>
            </table>
        <div class="pull-right">
            <?php
            $t=isset($_GET['tag'])?$_GET['tag']:'';
            $c=isset($_GET['cat'])?$_GET['cat']:'';
            $s=isset($_GET['s'])?$_GET['s']:'';
            if($t&&$c){
                $url = ['cat' => $c,'tag' => $t];
            }elseif($s){
                $url = ['s' => $s];
            }else{
                if($t){
                    $url = ['tag' => $t];
                }elseif($c){
                    $url = ['cat' => $c];
                }else{
                    $url = [];
                }
            }
            ?>
            {!! $Posts->appends($url)->render() !!}
        </div>
    </div>
@stop
@section('js')
    <script>
        (function () {
            $('#searchCon').on('click',function () {
                var url = $('#searchInput').val().replace(/(^\s*)|(\s*$)/g, "");
                if(url){
                    window.location.href= "{!! url('admin/posts?s=') !!}"+url;
                }else{
                    window.location.href= "{!! url('admin/posts') !!}"
                }
            });
            $('#searchMore').on('click',function () {
                var tag = $('#tag').val(),cat = $('#cat').val();
                if(tag!=0||cat!=0){
                    window.location.href= "{!! url('admin/posts?') !!}"+(tag==0?'':'tag='+tag)+(cat==0?'':'&cat='+cat);
                }else{
                    window.location.href= "{!! url('admin/posts') !!}"
                }
            });
        })()
    </script>
@stop